#include "Pet.h"

#include <iostream>

Pet::Pet()
{
}

Pet::~Pet()
{
}

void Pet::Init( sf::Image& image, int scrW, int scrH )
{
    m_dimensions.x = 17;
    m_dimensions.y = 22;
    m_action = 2;

    m_sprite.SetImage(image);
    m_sprite.SetSubRect( sf::IntRect( 0, m_action*m_dimensions.y,
                                      m_dimensions.x, (m_action+1)*m_dimensions.y ) );
    m_sprite.SetScale( 5.0f, 5.0f );
    m_sprite.SetCenter( m_dimensions.x/2, m_dimensions.y/2 );
    // Center horizontally
    m_sprite.SetPosition( scrW/2 - m_sprite.GetCenter().x, 80 );

    m_frame = 0;
    m_maxFrame = 5;

    // Init stats
    m_stats.hunger      = 100;
    m_stats.fitness     = 100;
    m_stats.happiness   = 100;
    m_stats.energy      = 100;
}

void Pet::IncrementFrame()
{
    m_frame += 0.1f;
    if ( m_frame >= m_maxFrame ) { m_frame = 0; }

    m_sprite.SetSubRect( sf::IntRect( (int)m_frame*m_dimensions.x, m_action*m_dimensions.y,
                                     ((int)(m_frame+1)*m_dimensions.x), (m_action+1)*m_dimensions.y ) );
}

void Pet::DecreaseStats()
{
    m_stats.hunger      -= 0.1;
    m_stats.happiness   -= 0.01;
    m_stats.energy      -= 0.5;

    std::cout<<std::endl;
    std::cout<<"Hunger:\t"      <<m_stats.hunger<<std::endl;
    std::cout<<"Fitness:\t"     <<m_stats.fitness<<std::endl;
    std::cout<<"Happiness:\t"   <<m_stats.happiness<<std::endl;
    std::cout<<"Energy:\t"      <<m_stats.energy<<std::endl;
}

void Pet::Update()
{
    IncrementFrame();
    DecreaseStats();
}
